The Demographic Prisoner's Dilemma is a family of variants on the classic two-player Prisoner's Dilemma, first developed by Joshua Epstein. The model consists of agents, each with a strategy of either Cooperate or Defect. Each agent's payoff is based on its strategy and the strategies of its spatial neighbors. After each step of the model, the agents adopt the strategy of their neighbor with the highest total score.
The specific variant presented here is adapted from the Evolutionary Prisoner's Dilemma model included with NetLogo. Its payoff table is a slight variant of the traditional PD payoff table:
| **Cooperate** | **Defect** | |
| **Cooperate** | 1, 1 | 0, *D* |
| **Defect** | *D*, 0 | 0, 0 |
Where D is the defection bonus, generally set higher than 1. In these runs, the defection bonus is set to $D=1.6$.
The Demographic Prisoner's Dilemma demonstrates how simple rules can lead to the emergence of widespread cooperation, despite the Defection strategy dominiating each individual interaction game. However, it is also interesting for another reason: it is known to be sensitive to the activation regime employed in it.
Below, we demonstrate this by instantiating the same model (with the same random seed) three times, with three different activation regimes:
In [1]:
from pd_grid import PD_Model
import random
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec
%matplotlib inline
In [2]:
bwr = plt.get_cmap("bwr")
def draw_grid(model, ax=None):
'''
Draw the current state of the grid, with Defecting agents in red
and Cooperating agents in blue.
'''
if not ax:
fig, ax = plt.subplots(figsize=(6,6))
grid = np.zeros((model.grid.width, model.grid.height))
for agent, x, y in model.grid.coord_iter():
if agent.move == "D":
grid[y][x] = 1
else:
grid[y][x] = 0
ax.pcolormesh(grid, cmap=bwr, vmin=0, vmax=1)
ax.axis('off')
ax.set_title("Steps: {}".format(model.schedule.steps))
In [3]:
def run_model(model):
'''
Run an experiment with a given model, and plot the results.
'''
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(231)
ax2 = fig.add_subplot(232)
ax3 = fig.add_subplot(233)
ax4 = fig.add_subplot(212)
draw_grid(model, ax1)
model.run(10)
draw_grid(model, ax2)
model.run(10)
draw_grid(model, ax3)
model.datacollector.get_model_vars_dataframe().plot(ax=ax4)
In [4]:
# Set the random seed
seed = 21
In [5]:
random.seed(seed)
m = PD_Model(50, 50, "Sequential")
run_model(m)
In [6]:
random.seed(seed)
m = PD_Model(50, 50, "Random")
run_model(m)
In [7]:
random.seed(seed)
m = PD_Model(50, 50, "Simultaneous")
run_model(m)
In [ ]: